/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.web.attence;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unis.common.ui.jqGrid.GridUIMapper;
import com.unis.common.util.WebUtil;
import com.unis.model.BaseModel;
import com.unis.model.attence.DutySystem;
import com.unis.service.attence.DutySystemService;

/**
 * @author Administrator (email:raulcsj@163.com)
 * @since 2013-01-31
 */
@Controller
@RequestMapping("/dutysystem")
public class DutySystemController {

    private DutySystemService dutysystemService;

    /****************************************
     * Insert a instace of DutySystem
     ****************************************/
    @RequestMapping("/insert")
    @ResponseBody
    public Object insertDutySystem(@RequestBody DutySystem dutysystem) throws Exception {
        dutysystem.setStatmentId("DutySystem.insert");
        String status = "failure";
        dutysystemService.insert(dutysystem);
        status = "success";
        return status;
    }

    /****************************************
     * Update a instace of DutySystem
     ****************************************/
    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody DutySystem dutysystem) throws Exception {
        dutysystem.setStatmentId("DutySystem.update");
        String status = "failure";
        dutysystemService.update(dutysystem);
        status = "success";
        return status;
    }

    /****************************************
     * Delete a instace of DutySystem
     ****************************************/
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody DutySystem dutysystem) throws Exception {
        dutysystem.setStatmentId("DutySystem.delete");
        String status = "failure";
        dutysystemService.batchDelete(dutysystem);
        status = "success";
        return status;
    }

    /****************************************
     * Query instaces of DutySystem
     ****************************************/
    @RequestMapping("/queryAsList")
    @ResponseBody
    public Object queryAsList(HttpServletRequest request) throws Exception {
        Map<String, Object> paramMap = WebUtil.getParamsMapFromRequest(request);
        DutySystem dutysystem = new DutySystem();
        dutysystem.setStatmentId("DutySystem.queryAsList");
        BeanUtils.populate(dutysystem, paramMap);
        Map<String, Object> pageMap = GridUIMapper.process(paramMap);
        BeanUtils.populate(dutysystem, pageMap);
        List<BaseModel> dutysystemList = dutysystemService.queryAsList(dutysystem);
        Map<String, Object> renderMap = GridUIMapper.render(dutysystem, dutysystemList);
        return renderMap;
    }

    /****************************************
     * Query a instaces of DutySystem
     ****************************************/
    @RequestMapping("/queryAsObject")
    @ResponseBody
    public BaseModel queryAsObject(@RequestBody DutySystem dutysystem) throws Exception {
        dutysystem.setStatmentId("DutySystem.queryAsObject");
        return dutysystemService.queryAsObject(dutysystem);
    }

    @RequestMapping("/page")
    public String forword() {
        return "attence/dutysystemList";
    }

    @Resource
    public void setDutySystemService(DutySystemService dutysystemService) {
        this.dutysystemService = dutysystemService;
    }
}
